<?php

class IndexAction extends CommonAction {
    public function index(){

        $info = $this->buildSeo("ch_index" );
        $this->page_title = $info["page_title"];
        $this->page_keyword = $info["page_keyword"];
        $this->page_description =$info["page_description"];
        $this->assign("config",$info['config']);

        $login=array("status"=>0);
        $city=array();
        $this->assign("city",$city);
        $this->assign("urlpath",C("PATH_URL"));

        $menu_id="index";//当前的模块信息

        $in_zone=M("myads")->where(array('zoneid'=>1))->order("orders asc")->select();
       // echo M()->getLastSql();
 //dump($in_zone);
        $this->assign("in_zone",$in_zone);


        $aboutlist=M('about')->where(array('elite'=>1))->select();
        $this->assign("aboutlist",$aboutlist);

        $s_gender=2;// 2 女会员 1男会员
        $this->assign("s_gender",$s_gender);

        $s_age1=28;
        $this->assign("s_age1",$s_age1);


        $article=M("article")->where(array())->order("articleid desc")->limit(0,4)->select();
        //dump($article);die();
        $this->assign("article",$article);

        $story=M("story")->where(array())->order("storyid desc")->limit(0,3)->select();
        $this->assign("story",$story);


        $dynamic=M("dynamic")->where(array())->order("dyid desc")->limit(0,5)->select();
        $this->assign("dynamic",$dynamic);


        $party=M("party")->where(array())->order("partyid desc")->limit(0,4)->select();
        $this->assign("party",$party);





        $s_dist=array();
        $areasar=M('area')->field("areaid,areaname,depth")->where(array())->order("areaid desc")->select();
        foreach($areasar as $key=>$val)
        {
            if($val['depth']==0)
                $s_dist[$val['areaid']]=$val['areaname'];
            $areas[$val['areaid']]=$val['areaname'];
        }

         //dump($s_dist);die;
        $this->assign("s_dist1",0);
        $this->assign("s_dist",$s_dist);



        $this->assign("areas",$areas);

        $this->assign("time",time());





        //女孩
        $girls=M("user")->where(array('elite'=>1,'avatar'=>1 ,'gender'=>2))->order("userid desc")->limit(0,10)->select();
        $this->assign("girls",$girls);


        $boys=M("user")->where(array('elite'=>1,'avatar'=>1 ,'gender'=>1))->order("userid desc")->limit(0,10)->select();
        $this->assign("boys",$boys);

        $newbees=M("user")->where(array( 'avatar'=>1  ))->order("userid desc")->limit(0,10)->select();
        $this->assign("newbees",$newbees);


        $storycat = M("item_options")->field("itemvalue")->where(array("itemname" => 'storycat'))->find();
        $storycat=$storycat['itemvalue'];
        $tpstorycate=explode("|",$storycat);
        $storycatar=array();
        foreach($tpstorycate as $key=>$val)
        {
            $tpa=explode("#",$val);
            $storycatar[$tpa[0]]=$tpa[1];
        }
        $this->assign("storycat",$storycatar);


        //地区
        $citytype_list=$this->getoptions("citytype");
        $this->assign("citytype_list",$citytype_list);

        //婚姻状况
        $marryopt=$this->getoptions("marry");
        $this->assign("marryopt",$marryopt);






        $partycat = M("item_options")->field("itemvalue")->where(array("itemname" => 'partycat'))->find();
        $partycat = $partycat['itemvalue'];


//die($partycat);
        $pcat = explode("|", $partycat);
        foreach($pcat as $key=>$val)
        {
            $partycatlist[]=explode("#",$val);
        }

        //dump($partycatlist);die;
        $this->assign("partycatlist", $partycatlist);






        $marry=M("marry")->where(array())->order("marryid desc")->limit(0,3)->select();
        foreach($marry as $key=>&$val)
        {
            $val['gallery'] =
                array(
                    array('thumb' => $val['thumbimg1'], 'img' => $val['img1']),
                    array('thumb' => $val['thumbimg2'], 'img' => $val['img2']),
                    array('thumb' => $val['thumbimg3'], 'img' => $val['img3']),
                    array('thumb' => $val['thumbimg4'], 'img' => $val['img4']),
                    array('thumb' => $val['thumbimg5'], 'img' => $val['img5']),
                    array('thumb' => $val['thumbimg6'], 'img' => $val['img6'])
                );

        }
        $this->assign("marry",$marry);



        $s_catid=0;
        $this->assign("s_catid",$s_catid);


        $this->assign("menu_id",$menu_id);

        $this->assign("login",$login);

        $this->display();

    }

    protected function  getoptions($optionname)
    {

        $marrystr= M("item_options")->field("itemvalue")->where(array("itemname" => $optionname))->find();
        $marrystr=$marrystr["itemvalue"];
        $marrycate=explode("|",$marrystr);
        $data=array();
        foreach($marrycate as $k=>$val)
        {
            $tpa=explode("#",$val);
            $data[$tpa[0]]=$tpa[1];
        }
        return $data;

    }


    public function test()
    {
        $this->display();
    }

    public function city()
    {

        $user=M("user")->limit(0,20)->order('userid desc')->select();
      // dump($user);die;
        $this->assign("user", $user);
        $this->display();
    }

}